import { Controller, Get, Query, UseGuards } from '@nestjs/common';
import { StatisticsService } from './statistics.service';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { GetUser } from '../common/decorators/get-user.decorator';
import { User } from '../users/entities/user.entity';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
  ApiQuery,
} from '@nestjs/swagger';

@ApiTags('统计')
@Controller('statistics')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
export class StatisticsController {
  constructor(private readonly statisticsService: StatisticsService) {}

  @Get('completion-trend')
  @ApiOperation({ summary: '获取任务完成率趋势' })
  @ApiResponse({ status: 200, description: '成功获取完成率趋势数据' })
  @ApiQuery({
    name: 'days',
    required: false,
    type: Number,
    description: '天数，默认为7天',
  })
  getCompletionTrend(@GetUser() user: User, @Query('days') days?: number) {
    return this.statisticsService.getCompletionTrend(user, days ? +days : 7);
  }

  @Get('category-distribution')
  @ApiOperation({ summary: '获取任务分类分布' })
  @ApiResponse({ status: 200, description: '成功获取分类分布数据' })
  getCategoryDistribution(@GetUser() user: User) {
    return this.statisticsService.getCategoryDistribution(user);
  }

  @Get('summary')
  @ApiOperation({ summary: '获取任务概览' })
  @ApiResponse({ status: 200, description: '成功获取任务概览数据' })
  getTasksSummary(@GetUser() user: User) {
    return this.statisticsService.getTasksSummary(user);
  }
}
